package com.wb3.meta.common.authentication;


public class RequestHolder {
    private static final ThreadLocal<AuthAddress> threadLocal = new ThreadLocal();

    public static void setAuthAddress(AuthAddress authAddress) {
        threadLocal.set(authAddress);
    }

    public static AuthAddress currentUser() {
        AuthAddress authAddress = threadLocal.get();
        if (authAddress == null)
            return new AuthAddress();
        return authAddress;
    }


    public static Integer getUserId() {
        Integer userId = null;
        AuthAddress authAddress = threadLocal.get();
        if (authAddress != null) {
            userId = authAddress.getId();
        }
        return userId;
    }


    public static void clear() {
        threadLocal.remove();
    }
}
